/**
 * Copyright 2016-2017 TVI Go Easy.
 * Created on 2017/4/17 22:47
 */
package org.mechanic.fund.web.product;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.mechanic.core.web.MediaTypes;
import org.mechanic.fund.domain.product.ProductStatus;
import org.mechanic.fund.service.product.IProductStatusService;
import org.mechanic.fund.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 募集状态 API
 *
 * @author mechanic
 * @version 0.0.1
 */
@Api(value = "募集状态接口")
@RestController
@RequestMapping(value = "product/status")
public class ProductStatusController extends BaseController {

    private final IProductStatusService statusService;

    @Autowired
    public ProductStatusController(IProductStatusService statusService) {
        this.statusService = statusService;
    }

    @ApiOperation(value = "返回募集状态列表")
    @GetMapping(value = "list", produces = MediaTypes.JSON_UTF_8)
    public Object list() {
        List<ProductStatus> statuses = this.statusService.getProductStatusList();
        return result(statuses);
    }

    @ApiOperation(value = "批量保存募集状态")
    @PutMapping(value = "save", consumes = MediaTypes.JSON_UTF_8)
    public Object save(
      @ApiParam(value = "募集状态集合", required = true) @RequestBody(required = true)
        List<ProductStatus> productStatuses) {
        this.statusService.save(productStatuses, super.currUser().getId());
        return result();
    }

    @ApiOperation(value = "按 ID 删除募集状态")
    @DeleteMapping(value = "delete/{id}", produces = MediaTypes.JSON_UTF_8)
    public Object delete(
      @ApiParam(value = "募集状态 ID", required = true) @PathVariable(required = true) String id) {
        this.statusService.delete(id);
        return result();
    }
}
